/**
 * ...
 * @author HTML5
 */

function Camera() 
{
	this.transformGroup = new CameraGroup();
	this._transformData = [0,0,0,0,0,0];
	this.transformGroup.name = "cameraGroup";
}

Camera.prototype.pivotX 		= 0; 
Camera.prototype.pivotY 		= 0; 
Camera.prototype.pivotZ 		= 0; 
Camera.prototype.x 				= 0; 
Camera.prototype.y 				= 0; 
Camera.prototype.z 				= 0; 
Camera.prototype.width 			= 0; 
Camera.prototype.height 		= 0; 
Camera.prototype.zoom 			= 1; 
Camera.prototype.rotationX 		= 0; 
Camera.prototype.rotationY 		= 0; 
Camera.prototype.rotationZ 		= 0; 
Camera.prototype.name			= "camera";

Camera.prototype.bounds			= {"x":0,"y":0,"width":0,"height":0};
Camera.prototype.hasChanged 	= true;
Camera.prototype.transformGroup = null;
Camera.prototype._transformData  = null;

Camera.prototype.update = function()
{
	var hasChanged = false;
	var transformedData = this.transformData;
	var data = null;
	
	this.x 		>>= 0;
	this.y 		>>= 0;
	this.z 		>>= 0;
	this.width 	>>= 0;
	this.height >>= 0;
	this.pivotX >>= 0;
	this.pivotY >>= 0;
	this.pivotZ >>= 0;
	this.rotationX = ( this.rotationX % 360 ) >> 0;
	this.rotationY = ( this.rotationY % 360 ) >> 0;
	this.rotationZ = ( this.rotationZ % 360 ) >> 0;
	
	this.transformGroup.x = this.x;
	this.transformGroup.y = this.y;
	this.transformGroup.z = this.z;
	this.transformGroup.pivotX = this.pivotX;
	this.transformGroup.pivotY = this.pivotY;
	this.transformGroup.pivotZ = this.pivotZ;
	this.transformGroup.rotationX = this.rotationX;
	this.transformGroup.rotationY = this.rotationY;
	this.transformGroup.rotationZ = this.rotationZ;
	
	this.transformGroup.scaleX = this.zoom;
	this.transformGroup.scaleY = this.zoom;
	this.transformGroup.scaleZ = 1;
						
	
	this.transformGroup.update( new Date().getTime() );
	data = this.transformGroup.transformData;
	
	this.hasChanged = ( 
							this._transformData[0] 	 	!= data[0] 	|| 
							this._transformData[1] 	 	!= data[1] 	|| 
							this._transformData[2] 	 	!= data[2] 	|| 
							this._transformData[3] 	 	!= data[3] 	|| 
							this._transformData[4] 	 	!= data[4] 	|| 
							this._transformData[5] 	 	!= data[5] 
					);
					
	this._transformData = data;
	
	if( this.hasChanged )
	{
		var cam_w = this.width / this.zoom;
		var cam_h = this.height / this.zoom;
		
		var cam_x = this.x + this.pivotX - ( this.pivotX / this.zoom );
		var cam_y = this.y + this.pivotY - ( this.pivotY / this.zoom );
		
		this.bounds = {"x":cam_x,"y":cam_y,"width":cam_w,"height":cam_h};
	}
	
	return this.hasChanged;
};